# coding=utf-8
# 代码文件：chapter1/ch1.8.2.py

a = 'Hello'
print('a[1:3] = ', a[1:3])          # 切出1~3的子字符串，注意不包括3返回el
print('a[:3] = ', a[:3])            # 省略了开始索引，默认开始索引是0返回Hel

print('a[0:3] = ', a[0:3])          # a[:3]与a[0:3]切片结果是一样返回Hel

print('a[0:5] = ', a[0:5])          # 省略了结束索引所以a[0:]与a[0:5]切片结果是一样的
print('a[:] = ', a[:])              # Hello
print('a[1:-1] = ', a[1:-1])        # ell

print('a[1:5] = ', a[1:5])          # 省略了步长参数，步长默认值是1返回ello
print('a[1:5:2] = ', a[1:5:2])      # 步长为2，结果是el返回el
print('a[0:3] = ', a[0:3])          # 步长为3，切片结果是H
print('a[0:3:2] = ', a[0:3:2])      # Hl
print('a[0:3:3] = ', a[0:3:3])      # H
print('a[::-1] = ', a[::-1])        # 步长为负数时是从右往左获取元素切片结果是原始字符串的倒置返回结果olleH
